import time
import uvicorn
from fastapi import FastAPI, UploadFile, File
from fastapi.responses import StreamingResponse, FileResponse

app = FastAPI()

@app.get("/api/ccnet_downloadfile")
async def downloadFile():
    return StreamingResponse(open('./api_data/test.png', mode="rb"), media_type="image/png")

@app.post("/api/ccnet_uploadfile")
async def uploadFile(file: UploadFile = File(...)):
    content = await file.read()
    with open('./api_data/test.jpg', 'wb') as f:
        f.write(content)
        f.close()

    return {"filename": file.filename, "code":200}

if __name__=="__main__":
    uvicorn.run(app='file_api:app', host="0.0.0.0", port=19777)

